import 'dart:async';

import 'package:flutter/material.dart';

class ShadowContainer extends StatefulWidget {
  final Widget child;
  final AlignmentGeometry? alignment;
  final EdgeInsetsGeometry? padding;
  final Color? color;
  final Decoration? decoration;
  final Decoration? foregroundDecoration;
  final double? width;
  final double? height;
  final BoxConstraints? constraints;
  final EdgeInsets? margin;
  final Matrix4? transform;
  final AlignmentGeometry? transformAlignment;
  final Clip clipBehavior;
  final bool enable;
  final BorderRadius borderRadius;
  final FutureOr Function()? onTap;

  const ShadowContainer(
      {super.key,
      this.alignment,
      this.padding,
      this.color = Colors.white,
      this.decoration,
      this.foregroundDecoration,
      this.width,
      this.height,
      this.constraints,
      this.margin,
      this.transform,
      this.transformAlignment,
      this.clipBehavior = Clip.none,
      this.enable = true,
      this.borderRadius = BorderRadius.zero,
      this.onTap,
      required this.child});

  @override
  State<StatefulWidget> createState() {
    return _ShadowContainerState();
  }
}

class _ShadowContainerState extends State<ShadowContainer> {
  bool tapping = false;

  @override
  Widget build(BuildContext context) {
    return Material(
      child: Padding(
        padding: EdgeInsets.all(3) + (widget.margin ?? EdgeInsets.zero),
        child: InkWell(
          onTap: widget.onTap != null && !tapping
              ? () async {
                  setState(() {
                    tapping == true;
                  });
                  await widget.onTap?.call();
                  setState(() {
                    tapping == false;
                  });
                }
              : null,
          borderRadius: widget.borderRadius,
          child: Ink(
            height: widget.height,
            width: widget.width,
            padding: widget.padding,
            // color: color,
            decoration: widget.decoration ??
                BoxDecoration(
                  borderRadius: widget.borderRadius,
                  color: widget.enable ? widget.color : Color(0xfff1f1f1),
                  boxShadow: [
                    BoxShadow(
                        color: Colors.black26,
                        offset: Offset(0, widget.enable ? 1 : 0),
                        blurRadius: widget.enable ? 2 : 1)
                  ],
                ),
            child: ClipRRect(
              borderRadius: widget.borderRadius,
              child: widget.child,
            ),
          ),
        ),
      ),
      type: MaterialType.transparency,
    );
  }
}
